package v1

import (
	"ginblog/model"
	"ginblog/utils/errmsg"
	"github.com/gin-gonic/gin"
)

// 登录验证
func Login(c *gin.Context) {
	var data model.User
	_ = c.ShouldBindJSON(&data)
	code, token := model.Login(data.Username, data.Password)
	if code == errmsg.SUCCESS {
		c.JSON(200, gin.H{
			"status":  code,
			"token":   token,
			"message": "登录成功",
		})
	} else {
		c.JSON(200, gin.H{
			"status":  code,
			"message": errmsg.GetErrMsg(code)})
	}
}
